package com.ayitubie.refuelweb.config;
import com.ayitubie.refuelweb.config.jedis.JedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.core.annotation.Order;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

@Component
@Order(1)
public class RedisDataLoader implements ApplicationListener<ApplicationReadyEvent> {
    @Autowired
    JedisService jedisService;
    private final StringRedisTemplate redisTemplate;

    public RedisDataLoader(StringRedisTemplate redisTemplate) {
        this.redisTemplate = redisTemplate;
    }

    @Override
    public void onApplicationEvent(ApplicationReadyEvent event) {
        loadDataToRedis();
    }

    private void loadDataToRedis() {
        redisTemplate.opsForValue().set("Version","1.0");
        jedisService.set("Author","麻槐德");
    }
}

